package org.swingplus.core.util;

import java.lang.reflect.Field;

public class PropertyManageUtil {

	
	public void setProperty(Object obj, String propertyName, Object value)
            throws NoSuchFieldException, SecurityException,
            IllegalArgumentException, IllegalAccessException {
        // 根绝对象获取字节码文件
        Class c = obj.getClass();
        // 获取该对象的propertyName成员变量
        Field field = c.getDeclaredField(propertyName);  //注意你是通过参数来获取，不许加双引号“”
        // 取消访问检查
        field.setAccessible(true);
        // 给对象的成员变量赋值为指定的值--->value
        field.set(obj, value);
    }
	
	public static void setPropertys(Object obj, String propertyName, Object value)
            throws NoSuchFieldException, SecurityException,
            IllegalArgumentException, IllegalAccessException {
        // 根绝对象获取字节码文件
        Class c = obj.getClass();
        // 获取该对象的propertyName成员变量
        Field field = c.getDeclaredField(propertyName);  //注意你是通过参数来获取，不许加双引号“”
        setProperty(obj,field,value);
    }
	
	public static void setProperty(Object obj,Field field,Object value)
            throws NoSuchFieldException, SecurityException,
            IllegalArgumentException, IllegalAccessException {
        // 取消访问检查
        field.setAccessible(true);
        // 给对象的成员变量赋值为指定的值--->value
        field.set(obj, value);
        field.setAccessible(false);
    }
	
}
